/**
 * Copyright (C) 2011-2021 liepin Inc.All Rights Reserved.
 * 
 * FileName:UserOrderDaoImpl.java
 *
 * Description：简要描述本文件的内容
 *
 * History：
 * 版本号           作者                  日期               简要介绍相关操作
 *  1.0  chenyong  2016年11月8日
 *
 */
package com.buybuyyi.stylistcrm.order.dao.impl;

import java.util.List;

import com.buybuyyi.stylistcrm.order.helper.OrderGoodsHelper;
import com.buybuyyi.stylistcrm.utils.DateUtil;
import com.buybuyyi.stylistcrm.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import stylistcrm.core.services.order.dto.OrderGoodsDto;
import stylistcrm.core.services.order.dto.PurchaseOrderDto;
import stylistcrm.core.services.order.dto.QueryOrderConditionDto;
import stylistcrm.core.services.order.dto.UserOrderDto;

import com.buybuyyi.stylistcrm.order.dao.UserOrderDao;
import com.buybuyyi.stylistcrm.order.mapper.UserOrderMapper;
import com.buybuyyi.stylistcrm.order.po.UserOrder;
import stylistcrm.core.services.order.enums.EnumOrderStatus;
import stylistcrm.core.services.order.enums.EnumOrderType;
import stylistcrm.core.services.order.enums.EnumPayWay;

/**
 * @author chenyong
 *
 */
@Repository
public class UserOrderDaoImpl implements UserOrderDao {
	
	@Autowired
	private UserOrderMapper userOrderMapper;

	@Override
	public int deleteByPrimaryKey(Integer id) {
		return userOrderMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(UserOrder record) {
		return userOrderMapper.insert(record);
	}

	@Override
	public int insertSelective(UserOrder record) {
		return userOrderMapper.insertSelective(record);
	}

	@Override
	public UserOrder selectByPrimaryKey(Integer id) {
		return userOrderMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(UserOrder record) {
		return userOrderMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(UserOrder record) {
		return userOrderMapper.updateByPrimaryKey(record);
	}

	@Override
	public List<UserOrderDto> getPageList(QueryOrderConditionDto queryCondition) {
		OrderGoodsHelper.setDefaultOrderBy(queryCondition, EnumOrderType.USER_ORDER);
		List<UserOrderDto> userOrderDtoList=userOrderMapper.getPageList(queryCondition);
		if(null!=userOrderDtoList&&0!=userOrderDtoList.size()){
			for(UserOrderDto userOrder:userOrderDtoList){
				List<OrderGoodsDto> orderGoodsDtoList=userOrder.getGoods();
				OrderGoodsHelper.setGoodsNameAndCount(orderGoodsDtoList,userOrder);
				if(StringUtil.isNotBlank(userOrder.getOrderStatus())){
					userOrder.setOrderStatus(EnumOrderStatus.getEnum(userOrder.getOrderStatus()).getDesc());
				}
				if(StringUtil.isNotBlank(userOrder.getPayWay())){
					userOrder.setPayWay(EnumPayWay.getEnum(userOrder.getPayWay()).getDesc());
				}
				if(StringUtil.isNotBlank(userOrder.getOrderTime())){
					userOrder.setOrderTime(DateUtil.formatDatetime(userOrder.getOrderTime()));
				}
				if(StringUtil.isNotBlank(userOrder.getPayTime())){
					userOrder.setPayTime(DateUtil.formatDatetime(userOrder.getPayTime()));
				}
			}
		}
		return userOrderDtoList;
	}

	@Override
	public Integer getTotalCount(QueryOrderConditionDto queryCondition) {
		return userOrderMapper.getTotalCount(queryCondition);
	}

}
